from odoo import models, fields, api, _
from odoo.exceptions import UserError, ValidationError


class ResPartner(models.Model):
    _inherit = 'res.partner'
    res_partner_codes_ids = fields.One2many('res.partner.codes', 'res_partner_id', string="Supplier Material Code List")

    @api.depends('name', 'code')  # need move
    def _compute_display_name(self):
        for rec in self:
            if rec.code and rec.name:
                rec.display_name = '[' + rec.code + ']' + rec.name
            else:
                rec.display_name = rec.name


class ResPartnerCodes(models.Model):
    _name = 'res.partner.codes'
    _description = 'Supplier Material Code Class'

    res_partner_id = fields.Many2one('res.partner', ondelete="cascade")
    product_tml_id = fields.Many2one('product.template', string="Product")
    product_coding_id = fields.Many2one('product.coding.template', string="Coding Template")
    serial_number = fields.Integer(string="Material Code")
